<template>
  <div>
    <input type="text" v-model="username" />
    <input type="password" v-model="password" />
    <button @click="login">登录</button>
  </div>
</template>

<script>
export default {
  data () {
    return {
      username: 'jack',
      password: '123456'
    }
  },
  methods: {
    login () {
      if (this.password === '123456') {
        // 把登录状态存到本地存储里面
        localStorage.setItem('isLogin', true)
        // 需要出发修改username的mutation
        // this.$store.commit('changeUsername', { username: this.username })
        // 触发action
        this.$store.dispatch('triggerChangeUname', { username: this.username })

        this.$router.push({ name: 'home' })
      } else {
        alert('用户名密码错误！')
      }
    }
  }
}
</script>

<style>
</style>
